package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyParkTicketTypeVo;
import com.ruoyi.system.bo.ZsyyParkTicketTypeQueryBo;
import com.ruoyi.system.bo.ZsyyParkTicketTypeAddBo;
import com.ruoyi.system.bo.ZsyyParkTicketTypeEditBo;
import com.ruoyi.system.service.IZsyyParkTicketTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 月票类型Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "月票类型控制器", tags = {"月票类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/parkTicketType")
public class ZsyyParkTicketTypeController extends BaseController {

    private final IZsyyParkTicketTypeService iZsyyParkTicketTypeService;

    /**
     * 查询月票类型列表
     */
    @ApiOperation("查询月票类型列表")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyParkTicketTypeVo> list(@Validated ZsyyParkTicketTypeQueryBo bo) {
        return iZsyyParkTicketTypeService.queryPageList(bo);
    }
    /**
     * 查询月票类型下拉列表
     */
    @ApiOperation("查询月票类型下拉列表")
    @GetMapping("/getAllList")
    public AjaxResult getAllList(@Validated ZsyyParkTicketTypeQueryBo bo) {
        return AjaxResult.success(iZsyyParkTicketTypeService.queryList(bo));
    }

    /**
     * 导出月票类型列表
     */
    @ApiOperation("导出月票类型列表")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:export')")
    @Log(title = "月票类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyParkTicketTypeVo> export(@Validated ZsyyParkTicketTypeQueryBo bo) {
        List<ZsyyParkTicketTypeVo> list = iZsyyParkTicketTypeService.queryList(bo);
        ExcelUtil<ZsyyParkTicketTypeVo> util = new ExcelUtil<ZsyyParkTicketTypeVo>(ZsyyParkTicketTypeVo.class);
        return util.exportExcel(list, "月票类型");
    }

    /**
     * 获取月票类型详细信息
     */
    @ApiOperation("获取月票类型详细信息")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyParkTicketTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyParkTicketTypeService.queryById(id));
    }

    /**
     * 新增月票类型
     */
    @ApiOperation("新增月票类型")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:add')")
    @Log(title = "月票类型", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyParkTicketTypeAddBo bo) {
        return toAjax(iZsyyParkTicketTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改月票类型
     */
    @ApiOperation("修改月票类型")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:edit')")
    @Log(title = "月票类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyParkTicketTypeEditBo bo) {
        return toAjax(iZsyyParkTicketTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除月票类型
     */
    @ApiOperation("删除月票类型")
    @PreAuthorize("@ss.hasPermi('system:parkTicketType:remove')")
    @Log(title = "月票类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyParkTicketTypeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
